
import java.awt.Button;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.BoxLayout;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

public class Pronk implements ActionListener{

	protected ArrayList<InventoryItem> inventoryPronk; 
	protected ArrayList<JCheckBox> boxenList;
	protected ArrayList<JLabel> deviceLabelList, modelLabelList;
	private JFrame listFrame;
	private JPanel listPanel;
	private Button deleterButton; 
	private InventoryList iL;


	//Parameters To add:  
	public Pronk(InventoryList guiAccess, String location,String user, ArrayList<InventoryItem> inventoryList){

		inventoryPronk = inventoryList;
		boxenList = new ArrayList<JCheckBox>();
		deviceLabelList = new ArrayList<JLabel>();
		modelLabelList = new ArrayList<JLabel>();
		iL = guiAccess;

		JPanel mainPanel;
		JPanel buttonPanel;

		listFrame = new JFrame("Delete Me After Testing");

		mainPanel = new JPanel();
		buttonPanel = new JPanel();
		this.listPanel = new JPanel();

		;
		this.deleterButton = new Button("Delete Selected");

		//MainFrame Setup
		listFrame.setSize(350,425);
		listFrame.setVisible(true);

		mainPanel.setSize(350,400);
		mainPanel.setLayout(new BoxLayout(mainPanel,BoxLayout.PAGE_AXIS));

		this.listPanel.setLayout(new GridLayout(0,3,0,0));

		buttonPanel.add(deleterButton);
		//		buttonPanel.add(closerButton);

		mainPanel.add(new JScrollPane(this.listPanel));
		mainPanel.add(buttonPanel);

		buttonPanel.setVisible(true);
		this.listPanel.setVisible(true);

		listFrame.add(mainPanel);

		//		this.closerButton.addActionListener(this);
		this.deleterButton.addActionListener(this);




		for(int j = 0; j < inventoryPronk.size(); ++j){
			InventoryItem device = inventoryPronk.get(j);


			JCheckBox tempBox = device.getItemCheckBox();
			JLabel tempDeviceLabel = device.getItemDeviceLabel();
			JLabel tempModelLabel = device.getItemModelLabel();

			boxenList.add(tempBox);
			deviceLabelList.add(tempDeviceLabel);
			modelLabelList.add(tempModelLabel);

			this.listPanel.add(tempBox);
			this.listPanel.add(tempDeviceLabel);
			this.listPanel.add(tempModelLabel);
		}
		listFrame.repaint();
	}

	public void pronkItOut(){

		InventoryItem device; 
		JCheckBox tempBox;
		for(int a = 0; a < inventoryPronk.size(); ++a){
			device = inventoryPronk.get(a);
			tempBox = device.getItemCheckBox();
			if(tempBox.isSelected()){
				//	System.out.println("Going to Remove: " + device.getItemSerial() + " " +device.getIndexInt());
				inventoryPronk.remove(device);
			}			
		}

		this.iL.setInventory(inventoryPronk);
		this.iL.repopTextArea();
		this.listPanel.repaint();

	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		// TODO Auto-generated method stub

		if(arg0.getSource() == deleterButton){
			this.pronkItOut();
			//System.out.println("Deleter Clicked!");

			this.listFrame.setVisible(false);
		}
	} // ends actionPerformed
	
	
	
} // Ends Pronk Class
